#include "http.hpp"
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <unordered_map>
//#define indexurl std::string("wwwroot/")

/*bool ObtainTheFileContent(std::string path,std::string* buf)
{
    /// 不去做任何处理，直接读取二进制数据
    std::ifstream is(path,std::ios::binary);
    if(is.is_open() == false)
    {
        printf("OPEN %s FILE FAILED!!", path.c_str());
        return false;
    }
    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);
    // read data as a block:
    buf->resize(length); //开辟文件大小的空间
    is.read(&(*buf)[0], length);
    is.close();
    return true;
}*/
int main()
{
    std::vector<std::string> v;
    std::string ss = "username=123456&passwd=123444";
    HTTP::Util::Split(ss,"&",v);
    for(auto result : v)
    {
        std::cout<<"["<<result.c_str()<<"]"<<std::endl;
    }
    /*std::string text;
    HTTP::Util::ObtainTheFileContent("../echo/echo.cc",&text);
    std::string path = "copy.txt";
    HTTP::Util::WriteToTheFile(path,&text);
    std::string s = "C++";
    std::cout << "s: " << s << std::endl;
    std::string res = HTTP::Util::UrlDecode(s,false);
    std::cout << "res: " << res << std::endl;
    std::string res2 = HTTP::Util::UrlEncode(s,false);
    std::cout << "res2: " << res2 << std::endl;
    std::unordered_map<std::string,std::string> _headers;
    _headers.insert(std::make_pair("Content-Length","200"));
    _headers.insert(std::make_pair("Connection","keep-alive"));
    _headers.insert(std::make_pair("Content-Type","text/html"));


    int status = 400;
    //std::string s = "NOT FOUND";
    std::string path = indexurl; 
    //path.append(s);
    std::string s = std::to_string(status)+".html";
    path.append(s);
    std::string body;
    ObtainTheFileContent(path,&body);
    std::stringstream ss;
    ss << "HTTP/1.1" << " " << std::to_string(status) << " " << "OK" << "\r\n";
    for(auto parm:_headers)
    {
        std::string key = parm.first;
        std::string val = parm.second;
        ss << key << ":" << val << "\r\n";
    }
    ss << "\r\n";
    ss << body;
    std::string s55 = ss.str();
    std::cout << s55.c_str() << std::endl;*/
    return 0;
}